package ren.colorful.learnjdk;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;

import org.junit.Test;

public class ListDemo {


	@SuppressWarnings("rawtypes")
	@Test
	public void testListOf(){
		final List<String> strList = new ArrayList<String>();
		strList.add("Hello");
		strList.add("world");
//		Optional.of(strList).ifPresent(list -> new Consumer<ArrayList>(){
//
//			@Override
//			public void accept(ArrayList t) {
//				
//			}
//			
//		});
		Optional.ofNullable(strList).map(list -> {
			List<String> result = new ArrayList<String>();
			list.forEach(i -> {
				result.add(i + "abc");
			});
			return result;
		}).get().forEach(bean -> {
			System.out.println(bean);
		});
		
		Optional.ofNullable(strList).map(new MyFunction()).orElse(new ArrayList<String>()).forEach(bean -> {
			System.out.println(bean);
		});
		
		Optional.of(strList).map(new Function<List<String>,List<String>>(){

			@Override
			public List<String> apply(List<String> t) {
				return null;
			}
			
		}).orElse(new ArrayList<String>());
		
		Object o = 23L;
		long a = (long)Optional.of(o).orElse(0L);
		System.out.println(a);
		
		System.out.printf("abc %h",12);
	}
	
	class MyFunction implements Function<List<String>,List<String>>{

		@Override
		public List<String> apply(List<String> t) {
			return null;
		}

		
	}
}
